package com.ltkj.system.api.factory;

import com.ltkj.common.core.domain.R;
import com.ltkj.common.core.web.domain.AjaxResult;
import com.ltkj.system.api.RemoteShopService;
import com.ltkj.system.api.domain.ShopGoodsDTO;
import com.ltkj.system.api.domain.ShopHotelDTO;
import com.ltkj.system.api.domain.ShopRestaurantDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 商城服务降级处理
 * 
 * @author ruoyi
 */
@Component
public class RemoteShopFallbackFactory implements FallbackFactory<RemoteShopService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteShopFallbackFactory.class);

    @Override
    public RemoteShopService create(Throwable throwable)
    {
        log.error("商城服务调用失败:{}", throwable.getMessage());
        return new RemoteShopService()
        {
            @Override
            public R<List<ShopGoodsDTO>> listGoods(ShopGoodsDTO shopGoods)
            {
                return R.fail("获取商品信息失败:" + throwable.getMessage());
            }

            @Override
            public R<List<ShopHotelDTO>> listHotel(ShopHotelDTO shopHotel) {
                return R.fail("获取酒店信息失败:" + throwable.getMessage());
            }

            @Override
            public R<List<ShopRestaurantDTO>> listRestaurant(ShopRestaurantDTO shopRestaurant) {
                return R.fail("获取餐饮信息失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult deleteCart(Long[] goodsIds, String[] types, Long userId) {
                return AjaxResult.error("清除购物车信息失败" + throwable.getMessage());
            }

            @Override
            public AjaxResult deleteCartByIds(Long[] ids) {
                return AjaxResult.error("清除购物车信息失败" + throwable.getMessage());
            }

        };
    }
}
